<template>
    <div class="header-main">
        <div class="box-l">
            <i :class="this.$store.state.menu.stretchBtnIconStatus ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
                @click="clickStretchBtn()" class="stretch-btn"></i>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item v-for="item in breadcrumb" :key="item.id" style="font-size: 14px;">{{ item.name }}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="box-r">
            <div class="box-screen"><i class="el-icon-full-screen"></i></div>
            <div class="box-renovate"><i class="el-icon-refresh-right"></i></div>
            <div class="box-message">
                <i class="el-icon-bell"></i>
                <div class="drop"></div>
            </div>
            <div class="box-header-img">
                <p class="admin-name">{{ adminInfo.name }}</p>
                <el-avatar :size="30" :src="adminInfo.url" @error="errorHandler">
                    <el-avatar :src="adminInfo.url"></el-avatar>
                </el-avatar>
                <div class="login-box">
                    <p class="close-all" @click="updateAdmin()">修改资料</p>
                    <p class="close-other" @click="loginOut()">退出登录</p>
                </div>
            </div>
            <div class="system" @click="drawer = true">
                <i class="el-icon-setting"></i>
            </div>
        </div>

        <el-drawer :withHeader=false :visible.sync="drawer" :direction="'rtl'" size="320px">
            <div class="drawer-main">
                <div class="header">
                    <h3>主题设置</h3>
                    <i class="el-icon-close" @click="drawer = false"></i>
                </div>
                <div class="line">
                    <div class="line-l"></div>
                    <p class="title">颜色配置</p>
                    <div class="line-r"></div>
                </div>
                <div class="block">
                    <div class="row">
                        <div class="row-l">
                            主菜单背景颜色
                        </div>
                        <div class="row-r">
                            <el-color-picker v-model="mainMenuBagColor" size="mini"
                                @change="setInterface($event, 'mainMenuBagColor')"></el-color-picker>
                        </div>
                    </div>
                </div>
                <div class="block">
                    <div class="row">
                        <div class="row-l">
                            主菜单hover颜色
                        </div>
                        <div class="row-r">
                            <el-color-picker v-model="mainHoverMenuBagColor" size="mini"
                                @change="setInterface($event, 'mainHoverMenuBagColor')"></el-color-picker>
                        </div>
                    </div>
                </div>
                <div class="line">
                    <div class="line-l"></div>
                    <p class="title">其它设置</p>
                    <div class="line-r"></div>
                </div>
                <div class="block">
                    <div class="row">
                        <div class="row-l">
                            点击遮罩层是否关闭弹出层
                        </div>
                        <div class="row-r">
                            <el-switch v-model="closeOnClickModal" @change="setInterface($event, 'closeOnClickModal')"
                                active-color="#13ce66" inactive-color="#ff4949">
                            </el-switch>
                        </div>
                    </div>
                </div>
                <div class="block">
                    <div class="row">
                        <div class="row-l">
                            点击菜单是否打开侧栏菜单
                        </div>
                        <div class="row-r">
                            <el-switch v-model="clickMenuIsOpenSideMenu"
                                @change="setInterface($event, 'clickMenuIsOpenSideMenu')" active-color="#13ce66"
                                inactive-color="#ff4949">
                            </el-switch>
                        </div>
                    </div>
                </div>
                <el-button class="resetting-btn" type="primary" size="mini" @click="resetting">重置</el-button>
            </div>
        </el-drawer>

        <!-- 修改资料 -->
        <x-update-admin ref="updateAdmin" />
    </div>
</template>
  
<script>
import { resetting } from '@/api/system/auth/authAdminConfig';
export default {
    name: "x-header",
    components: {
        'x-update-admin': () => import('@/components/common/xUpdateAdmin'),
    },
    data() {
        return {
            adminInfo: {},
            drawer: false,
            mainMenuBagColor: this.$store.state.theme.interface.color.mainMenuBagColor,
            mainHoverMenuBagColor: this.$store.state.theme.interface.color.mainHoverMenuBagColor,
            closeOnClickModal: this.$store.state.theme.interface.other.closeOnClickModal,
            clickMenuIsOpenSideMenu: this.$store.state.theme.interface.other.clickMenuIsOpenSideMenu,
        };
    },
    mounted() {
        this.adminInfo = JSON.parse(localStorage.getItem("adminInfo"));
    },
    methods: {
        errorHandler() {
            return true
        },
        clickStretchBtn: function () {
            this.$store.commit('changeStretchBtnIconStatus');
        },
        updateAdmin() {
            this.$refs.updateAdmin.dialogFormVisible = true;
        },
        loginOut() {
            localStorage.clear();
            this.$router.push({ name: "login" });
        },
        setInterface(e, type) {
            this.$store.commit('setInterface', {
                'type': type,
                'value': e
            });
            this.$router.go(0);
        },
        resetting() {
            resetting({
                'type': 1
            }).then(res => {
                this.$store.commit('initSiteThemeData', res.data);
                this.$router.go(0);
            })
        }
    },
    computed: {
        breadcrumb() {
            return this.$store.state.menu.menuData.breadcrumb.data;
        }
    }
}
</script>

<style scoped lang="less">
.header-main {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .box-l {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .stretch-btn {
            margin-right: 15px;
            color: #595959;
            cursor: pointer;
        }
    }

    .box-r {
        display: flex;
        justify-content: right;
        align-items: center;
        height: 100%;

        >div {
            display: flex;
            text-align: center;
            align-items: center;
            height: 100%;
            padding: 0 10px;
            box-sizing: border-box;
            cursor: pointer;
        }

        >div:hover {
            background-color: var(--bgGrey);
        }

        .box-message {
            .drop {
                width: 6px;
                height: 6px;
                background-color: #f56c6c;
                position: relative;
                top: -6px;
                right: 4px;
                border-radius: 50%;
            }
        }

        .site-name {
            height: 22px;
            font-size: 14px;
            border-radius: 10px;
            background-color: var(--bgDarkBlue);
            color: white;
        }

        .box-header-img {
            .admin-name {
                font-size: 14px;
                margin-right: 15px;
                color: var(--fondGrey);
            }

            &:hover>.login-box {
                height: 86px;
            }

            .login-box {
                width: 80px;
                height: 0px;
                background-color: #FFFFFF;
                position: absolute;
                top: 55px;
                right: 50px;
                overflow: hidden;
                align-items: center;
                text-align: center;
                transition: all 0.3s;
                transition-timing-function: ease;
                border-radius: 5px;
                z-index: 99;
                box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.6), -2px -2px 2px rgba(255, 255, 255, 1);

                p {
                    font-weight: 400;
                    font-size: 12px;
                    line-height: 24px;
                    color: var(--fondGrey);

                    &:hover {
                        color: #2D8CF0;
                        text-decoration: underline;
                    }
                }

                .close-all {
                    margin-top: 15px;
                }

                .close-other {
                    margin-bottom: 15px;
                }
            }
        }
    }
}

.drawer-main {
    width: 100%;
    height: 100%;
    padding: 15px;

    .header {
        height: 35px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        h3 {
            font-size: 14px;
            font-weight: 700;
        }

        i {
            font-size: 18px;
            cursor: pointer;
        }

        i:hover {
            color: red;
        }
    }

    .line {
        height: 32px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .line-l,
        .line-r {
            height: 1px;
            width: 36%;
            background-color: var(--borderGrey);
        }

        .title {
            font-size: 14px;
            color: var(--fondGrey);
        }
    }

    .block {
        font-size: 14px;

        .row {
            height: 32px;
            color: var(--fondGrey);
            line-height: 32px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }

    .resetting-btn {
        float: right;
        margin-top: 15px;
    }
}
</style>